﻿using System;
using Epm.AppLogic.Framework;
using msBsc.Xsd.DataTds;
using System.Data;

namespace msBsc.AppLogic.DataAlc
{
  public  class CBizShpOrderFormList: CustBizObject
    {
        private CDmShpOrderFormList m_CDmShpOrderFormList = new CDmShpOrderFormList();
        private CDmShpOrderFormList oDmShpOrderFormList
        {
            get { return m_CDmShpOrderFormList; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public CBizShpOrderFormList()
            : base()
        {
            this.DataObj = new CDbAccess();
            this.DataObj.Init(this.m_CDmShpOrderFormList.SHP_ORDER_FORM_LIST);
            this.TableName = this.DataObj.TableName;
            this.DataObj.KeyField = this.DataObj.Fields["ORDER_LIST_ID"]; 
            //this.DataObj.IdGroup = "RID";
        }

        /// <summary>
        /// 新增记录前的处理
        /// </summary>
        /// <param name="drw">新增数据行</param>
        /// <returns>true/false</returns>
        /// <remarks>
        /// 生成ID值
        /// </remarks>
        protected override bool BeforeRowAdded(DataRow drw)
        {
            if (drw[this.KeyFieldName].ToString().Length < 10)
            {
                drw[this.KeyFieldName] = this.DataObj.NewID();
            } 

            return true;
        }

        /// <summary>
        /// 记录修改前检验
        /// </summary>
        /// <param name="drw">当前记录</param>
        /// <returns>>校验合法，返回值为true,否则返回false</returns>
        /// <remarks>
        /// ID不允许修改,并把此修改操作记录到BSE_MODIFY_HISTORY表中
        /// </remarks>
        protected override bool BeforeRowModified(DataRow drw)
        {
            //ID不容许修改
            if (drw[this.KeyFieldName].ToString() != drw[this.KeyFieldName, DataRowVersion.Original].ToString())
            {
                Exception e = new Exception(this.TableName + "表的主键" + this.KeyFieldName + "字段不允许被修改");
                throw e;
            }
            return true;
        }

        public DataSet SelectByOrderId(string strOrderId)
        {
            DataSet ds = this.DataObj.QueryBySQL("SELECT * FROM " + this.TableName + " WHERE  ORDER_FORM_ID =  '" + strOrderId + "' ORDER BY SEQ_NUM ASC");
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }


        public DataSet SelectForShippingByOrderIdS(string strDealerId, string strOrderIdS)
        {
            DataSet ds = this.DataObj.QueryBySQL("SELECT A.*,B.USER_NME,B.BUY_MEMO,B.ORDER_FORM_NO,B.TO_ZONE_DESC,B.TO_STREET_ADDRESS,B.TO_ZIP_CODE,B.TO_RECEIPT_NME,B.TO_PHONE_NO,B.TO_LANDLINE_NO,B.PAID_AMT FROM " + this.TableName + " A LEFT OUTER JOIN SHP_ORDER_FORM B ON A.ORDER_FORM_ID=B.ORDER_FORM_ID WHERE  ( A.ORDER_FORM_ID IN  ('" + strOrderIdS.Replace("'", "").Replace(",", "','") + "')) AND (B.COMM_TENANT_ID='" + strDealerId + "') ORDER BY A.ORDER_FORM_ID ASC,A.SEQ_NUM ASC");
            ds.Tables[0].TableName = this.TableName;
            return ds;
        } 

    }
}
